<?php

	require("includes/database.php");

	$inString = $_GET[q];
	$inOp = $_GET[op];
	$inId = $_GET[id];
	
	if ($inString != "")
	{
		
		switch($inOp)
		{
			case 1:
			{
				$sql = "SELECT idAccion FROM acciones WHERE codigo='" . $inString . "'";
				break;
			}
			case 2:
			{
				$sql = "SELECT idAccion FROM acciones WHERE codigo='" . $inString . "' and idAccion <>" . $inId;
				break;
			}
			case 3:
			{
				$sql = "SELECT idFalla FROM fallas WHERE codigo='" . $inString . "'";
				break;
			}
			case 4:
			{
				$sql = "SELECT idFalla FROM fallas WHERE codigo='" . $inString . "' and idFalla <>" . $inId;
				break;
			}
			case 5:
			{
				$sql = "SELECT idModelo FROM modelos WHERE codigo='" . $inString . "'";
				break;
			}
			case 6:
			{
				$sql = "SELECT idModelo FROM modelos WHERE codigo='" . $inString . "' and idModelo <>" . $inId;
				break;
			}
			case 7:
			{
				$sql = "SELECT idOperador FROM operadores WHERE codigo='" . $inString . "'";
				break;
			}
			case 8:
			{
				$sql = "SELECT idOperador FROM operadores WHERE codigo='" . $inString . "' and idOperador <>" . $inId;
				break;
			}
			case 9:
			{
				$sql = "SELECT idSintoma FROM sintomas WHERE codigo='" . $inString . "'";
				break;
			}
			case 10:
			{
				$sql = "SELECT idSintoma FROM sintomas WHERE codigo='" . $inString . "' and idSintoma <>" . $inId;
				break;
			}
			case 11:
			{
				$sql = "SELECT idParte FROM partes WHERE codigo='" . $inString . "'";
				break;
			}
			case 12:
			{
				$sql = "SELECT idParte FROM partes WHERE codigo='" . $inString . "' and idParte <>" . $inId;
				break;
			}
			case 15:
			{
				$sql = "SELECT idEquipo FROM equipos WHERE codigo='" . $inString . "'";
				break;
			}
			case 16:
			{
				$sql = "SELECT idEquipo FROM equipos WHERE codigo='" . $inString . "' and idEquipo <>" . $inId;
				break;
			}
			case 22:
			{
				$sql = "SELECT idUsuario FROM usuarios WHERE username='" . $inString . "'";
				break;
			}
			case 30:
			{
				$sql = "SELECT imei FROM stock WHERE imei = '$inString' and idParte = $inId and cantidad <> 0";
				break;
			}
			case 31:
			{
				$sql = "SELECT imei FROM stock WHERE imei = '" . $inString . "' and idParte = " . $inId;
				break;
			}
			case 32:
			{
				list($codigoTango, $nombre) = split(" - ", $inId);
				$sql = "SELECT idParte FROM partes WHERE codigoTango='" . $codigoTango . "'";
				$result = readSQL($sql);
				foreach($result as $value)
				{
					$idParte = $value[0];
				}
				$sql = "SELECT idParte FROM stock WHERE nroFactura = '" . $inString . "' and idParte = " . $idParte;
				break;
			}
			case 33:
			{
				$sql = "SELECT idParte FROM stock WHERE nroFactura = '" . $inString . "' and idParte = " . $inId;
				break;
			}
			case 34:
			{
				$sql = "SELECT idCliente FROM clientes WHERE nombre='" . $inString . "'";
				break;
			}
			case 35:
			{
				$sql = "SELECT idCliente FROM clientes WHERE nombre='" . $inString . "' and idCliente <>" . $inId;
				break;
			}
			case 36:
			{
				$sql = "SELECT idReceptoria FROM receptorias WHERE nombre='" . $inString . "'";
				break;
			}
			case 37:
			{
				$sql = "SELECT idReceptoria FROM receptorias WHERE nombre='" . $inString . "' and idReceptoria <>" . $inId;
				break;
			}
			case 38:
			{
				$sql = "SELECT idListaPrecio FROM listasprecios WHERE nombre='" . $inString . "'";
				break;
			}
			case 39:
			{
				$sql = "SELECT idListaPrecio FROM listasprecios WHERE nombre='" . $inString . "' and idListaPrecio <>" . $inId;
				break;
			}
			case 40:
			{
				$sql = "SELECT imei FROM ordenes WHERE imei='" . $inString . "' AND nroRemitoEmisor='" . $inId . "'";
				break;
			}
			case 41:
			{
				$sql = "SELECT idStockEnTransito FROM stockentransito WHERE nroRemito='" . $inString . "' AND idAlmacen IN(SELECT idAlmacen FROM almacenes WHERE idSucursal=" . $inId . ")";
				break;
			}
			case 42:
			{
				$sql = "SELECT idOrden FROM equipostransito WHERE nroRemito='" . $inString . "' AND idAlmacen IN(SELECT idAlmacen FROM almacenes WHERE idSucursal=" . $inId . ")";
				break;
			}
			case 43:
			{
				$sql = "SELECT idOrden FROM equipostransito WHERE nroRemito='" . $inString . "'";
				break;
			}
		}
		//echo $sql;
		
		$result = readSQL($sql);
	
		if (count($result) != 0)
			echo "Codigo EXISTENTE";

	}
?>
